package com.cxc.simple;

public class MyObject {

    private int counter;

    /**
     * 增加
     */
    public synchronized  void increate(){

      while (counter !=0 ){
          try{
              wait();
          }catch (InterruptedException ex){
              ex.printStackTrace();
          }
      }
        counter++;
        System.out.println(counter);
        notify();
    }

    public synchronized  void  decrease(){
        while (counter==0){
            try{
                wait();
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
        counter--;
        System.out.println(counter);
        notify();
    }
}
